package org.example.common.utils;

import org.example.common.exception.BadParamExcepion;

public class ParamFilter {

    private static final String[] availableSort;
    private static final String[] availableOrder;
    private static final String[] availableOrderType;


    static {
        availableSort = new String[]{
                "add_time",
                "update_time",
                "retail_price",
                "name",
                "sort_order"
        };
        availableOrder = new String[]{
                "asc",
                "desc"
        };
        availableOrderType = new String[]{
                "all",
                "submitted",
                "done"
        };

    }

    public static void sortFilter(String sort){

        for(String tempSort: availableSort){
            if(tempSort.equals(sort)){
                return;
            }
        }
        throw new BadParamExcepion("sort invalid");
    }

    public static void orderFilter(String order){

        for(String tempOrder: availableOrder){
            if(tempOrder.equals(order)){
                return;
            }
        }
        throw new BadParamExcepion("order invalid");
    }
    public static void orderTypeFilter(String type){

        for(String tempType: availableOrderType){
            if(tempType.equals(tempType)){
                return;
            }
        }
        throw new BadParamExcepion("order type invalid");
    }
}
